#!/usr/bin/perl


print "\nPlease enter the path to your FASTA file\n";

$name = <STDIN>;
chomp $name; 

open(FILE, $name) || die ("could not open file!");
@data = <FILE>; 
close(FILE);
print"\n FASTA sequence: \n @data\n";


#This will remove the header from the fasta file

foreach $line(@data)
{

 chomp($line);
 @seq = $line;
}

print "\n Sequence without FASTA header: \n @seq \n"; 

do{
print "\nPlease input potential forward primer 5' to 3' to test for primer specificity\n";
$primerf = <STDIN>;
chomp $primerf;
$count = 0; 
@primer_forward = $primerf;

while (<@seq>) 
{
      while (/$primerf/g) {
         $count++;
     }
}
print "\n Found $primerf $count times.\n";

#This Calculates the num of a,t,c,g
$countat = 0; #number of time A and T occur in primer
$countcg = 0;
while (<@primer_forward>)
{
	while (/a|t|A|T/g){
		$countat++;
	}	while (/c|g|C|G/g){
		$countcg++;
	}	
}

if($count == 1 )
{
	print " Number of a's and t's: $countat \n";
	print " Number of c's and g's: $countcg \n";
	$tempf=  (2*$countat) + (4*$countcg);
	print"\n This primer is sequence specific.\n Tm: $tempf C \n \n NOTE: Please make sure to check your primer for specificity on NCBI-BLAST!\n";
}
else
{
	print "\n ERROR! This forward primer is non specific please chose another one\n";
}
}while($count!=1);

#REVERSE PRIMER INPUT CODE
do{
$countr = 0; # number of times it occurs
# This allows the user to input a primer and make sure it does not occur multiple times in the sequence
print "\nPlease input potential reverse primer sequence 5' to 3'from initial sequence NOT the compliment sequence to test for primer specificity.\n";

$primerr = <STDIN>;
chomp $primerr;
@primer_reverse = $primerr;

#This Calculates the num of a,t,c,g
$countrat = 0; #number of time A and T occur in primer
$countrcg = 0;
while (<@primer_reverse>)
{
	while (/a|t/g){
		$countrat++;
	}		while (/c|g/g){
		$countrcg++;
	}
}


#This check for primer specificity by making sure it doesn't occur multiple times in the sequence.
while (<@seq>) 
{
      while (/@primer_reverse/g) {
         $countr++;
     }
}

print "\n Found $primerr $countr times.\n";

if($countr == 1 )
{	print " Number of a's and t's: $countrat \n";
	print " Number of c's and g's: $countrcg \n";
	$tempr=  (2*$countrat) + (4*$countrcg);
	print"\n This primer is sequence specific.\n Tm: $tempr C \n \n NOTE: Please make sure to check your primer for specificity on NCBI-BLAST!";
}

else
{
	print "\n ERROR! This forward primer is non specific please chose another one\n";
}
}while($countr!=1);

print "\n \nPush ENTER so the program checks to see if primer set Tm difference is ideal\n";
$tempdiff = <STDIN>;
$tempdiff = abs($tempr- $tempf);
print "Tm Difference: $tempdiff \n";
if($tempdiff > 2)
{
	print "This primer set's Tm differnce is not acceptable.";
}

else
{
	print "This primer set's Tm difference is in the ideal range.";
}